package com.ytktt.study.week3.task346.gateway.inbound;

import com.ytktt.study.week3.task346.gateway.filter.HttpRequestFilter;
import com.ytktt.study.week3.task346.gateway.outbound.httpclient4.HttpOutboundHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

@Component
@RequiredArgsConstructor
public class HttpInboundInitializer extends ChannelInitializer<SocketChannel> {

    private final HttpOutboundHandler handler;
    private final List<HttpRequestFilter> requestFilterList;

    @Override
    public void initChannel(SocketChannel ch) {
        ChannelPipeline p = ch.pipeline();
//		if (sslCtx != null) {
//			p.addLast(sslCtx.newHandler(ch.alloc()));
//		}
        p.addLast(new HttpServerCodec());
        //p.addLast(new HttpServerExpectContinueHandler());
        p.addLast(new HttpObjectAggregator(1024 * 1024));
        p.addLast(new HttpInboundHandler(this.handler, this.requestFilterList));
    }
}
